package com.cykj.web.controller.posbiz;;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.domain.BizPosType;
import com.cykj.pos.service.IBizPosTypeService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * POS机类型Controller
 *
 * @author weijianbo
 * @date 2021-05-18
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/type" )
public class BizPosTypeController extends BaseController {

    private final IBizPosTypeService iBizPosTypeService;

    /**
     * 查询POS机类型列表
     */
    @PreAuthorize("@ss.hasPermi('pos:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPosType bizPosType) {
        startPage();
        List<BizPosType> list = iBizPosTypeService.queryList(bizPosType);
        return getDataTable(list);
    }

    /**
     * 导出POS机类型列表
     */
    @PreAuthorize("@ss.hasPermi('pos:type:export')" )
    @Log(title = "POS机类型" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(BizPosType bizPosType) {
        List<BizPosType> list = iBizPosTypeService.queryList(bizPosType);
        ExcelUtil<BizPosType> util = new ExcelUtil<BizPosType>(BizPosType.class);
        return util.exportExcel(list, "type" );
    }

    /**
     * 获取POS机类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:type:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iBizPosTypeService.getById(id));
    }

    /**
     * 新增POS机类型
     */
    @PreAuthorize("@ss.hasPermi('pos:type:add')" )
    @Log(title = "POS机类型" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPosType bizPosType) {
        return toAjax(iBizPosTypeService.save(bizPosType) ? 1 : 0);
    }

    /**
     * 修改POS机类型
     */
    @PreAuthorize("@ss.hasPermi('pos:type:edit')" )
    @Log(title = "POS机类型" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPosType bizPosType) {
        return toAjax(iBizPosTypeService.updateById(bizPosType) ? 1 : 0);
    }

    /**
     * 删除POS机类型
     */
    @PreAuthorize("@ss.hasPermi('pos:type:remove')" )
    @Log(title = "POS机类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iBizPosTypeService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
